﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Agile.Service.Rbac
{
    /// <summary>
    /// 领域服务
    /// <para>超级管理员权限</para>
    /// <para>超级管理员使用guid.empty为ID，可以根据需要修改</para>
    /// </summary>
    public class SystemAuthStrategy : IAuthStrategy
    {
        private readonly ILoginInfo _loginInfo;
        private readonly IMenuService _menuService;
        private readonly IMenuElementService _menuElementService;
        private readonly IRoleService _roleService;
        private readonly IOrganizeService _organizeService;
        private readonly IUserService _userService;
        public SystemAuthStrategy(ILoginInfo loginInfo,
            IMenuService menuService,
            IMenuElementService menuElementService,
            IRoleService roleService,
            IUserService userService,
            IOrganizeService organizeService)
        {
            _loginInfo = loginInfo;
            _menuService = menuService;
            _menuElementService = menuElementService;
            _roleService = roleService;
            _organizeService = organizeService;
            _userService = userService;
        }
        public List<Menu> Modules
        {
            get
            {
                var list = _menuService.GetByAll();
                return list;
            }
        }
        public List<MenuElement> ModuleElements
        {
            get
            {
                var list = _menuElementService.GetByAll();
                return list;
            }
        }
        public List<Role> Roles
        {
            get
            {
                var list = _roleService.GetByAll();
                return list;
            }
        }
        public List<Organize> Organize
        {
            get
            {
                var list = _organizeService.GetByAll();
                return list;
            }
        }

        public User User
        {
            get
            {
                var model = _userService.GetByName(_loginInfo.AccountName);
                return model;
            }
            set//禁止外部设置
            {
                throw new Exception("超级管理员，禁止设置用户");
            }
        }

        public List<KeyValue> GetProperties(string moduleCode)
        {
            throw new NotImplementedException();
        }
    }
}
